package cn.edu.scau.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.scau.dao.CareMapper;
import cn.edu.scau.entity.Care;
import cn.edu.scau.service.CareService;

@Service
public class CareServiceImpl implements CareService{
	@Autowired
	CareMapper careMapper;

	@Override
	public boolean insert(Care care) {
		int line = careMapper.insertSelective(care);
		return line ==1? true:false;
	}

	@Override
	public boolean update(Care care) {
		int line = careMapper.updateByPrimaryKeySelective(care);
		return line ==1? true:false;
	}

	@Override
	public boolean delete(Integer customerid) {
		int line = careMapper.deleteByPrimaryKey(customerid);
		return line ==1? true:false;
	}

	@Override
	public Care selectByPrimaryKey(Integer customerid) {
		return careMapper.selectByPrimaryKey(customerid);
	}

	@Override
	public List<Care> selectAll() {
		return careMapper.selectAll();
	}

	@Override
	public List<Care> find(Integer customerid, String customername, Integer nurseid, String nursename) {
		if(customerid!=null&&customerid<1){
			customerid=null;
        }
        if(StringUtils.isBlank(customername)){
        	customername=null;
        }
        if(nurseid!=null&&nurseid<1){
        	nurseid=null;
        }
        if(StringUtils.isBlank(nursename)){
        	nursename=null;
        }
    	return careMapper.find(customerid, customername, nurseid, nursename);
    }

	@Override
	public List<Care> selectByNurseID(Integer nurseID) {
		if(nurseID!=null&&nurseID<1){
			System.out.println("根据护士编号查询照顾信息时护士编号错误");
			nurseID=null;
        }
		return careMapper.selectByNurseID(nurseID);
	}

	@Override
	public List<Care> findWithNurseID(Integer customerid, String customername, Integer nurseid, String nursename) {
		if(nurseid!=null&&nurseid<1){
			System.out.println("根据护士编号组合查询照顾信息时护士编号错误");
			nurseid=null;
        }
		return careMapper.findWithNurseID(customerid, customername, nurseid, nursename);
	}
}
